package br.com.escola;

import br.com.escola.util.FileUtil;

public class BoletoRegistraPagamento
{
	public static void main(String[] args)
	{
		try
		{
			StringBuffer sb      = new StringBuffer();
			int          k       = 0;
			String       dataArq = "2013-02-16";

			sb.append("<%@page import=\"java.util.Date\"%>\n<%@page import=\"br.com.colegio.dao.storage.BoletoData\"%><%\n");

			for (String s : FileUtil.pegaURL("e:/_escola/conta-corrente/boletos/boletos" + dataArq + ".csv", "\n").split("\n"))
			{
				String[] c = s.split(";");

				if (!c[20].replaceAll("'", "").trim().equals(""))
				{
					sb.append("out.print(BoletoData.getInstance().registrarPagamento(\"" + c[3].replaceAll("'", "").trim() + "\"," +
						"new Date(" + (Integer.parseInt(c[14].replaceAll("'", "").trim().split("/")[2]) - 1900) + "," +
						(Integer.parseInt(c[14].replaceAll("'", "").trim().split("/")[1]) - 1) + "," +
						Integer.parseInt(c[14].replaceAll("'", "").trim().split("/")[0]) + ")," +
						"\"BANCO\"," + 
						c[20].replaceAll("'", "").trim() + "," +
						Double.valueOf(c[15].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
						Double.valueOf(c[16].replaceAll("'", "").trim().replaceAll(",", ".")) + "," +
						Double.valueOf(c[17].replaceAll("'", "").trim().replaceAll(",", ".")) + ") + \"<br>\");\n");

					k++;

					if (k % 100 == 0)
					{
						sb.append("\n%>");
						FileUtil.write("E:/_escola/conta-corrente/boletos/carga/pagamento-boleto-" + dataArq + "_" + k + ".jsp", sb.toString());

						sb = new StringBuffer();
						sb.append("<%@page import=\"java.util.Date\"%>\n<%@page import=\"br.com.colegio.dao.storage.BoletoData\"%><%\n");
					}
				}
			}

			if (k % 100 != 0)
			{
				sb.append("\n%>");
				FileUtil.write("E:/_escola/conta-corrente/boletos/carga/pagamento-boleto-" + dataArq + "_" + k + ".jsp", sb.toString());
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
}
